# libc/hc08 Makefile

VPATH  = @srcdir@
srcdir = @srcdir@
top_builddir = @top_builddir@

AR_S            = @AR@ @AR_S_FLAG@

LIB_TYPE        = @LIB_TYPE@

TOPDIR = ../../..

SCC = $(TOPDIR)/bin/sdcc -mhc08
SAS = $(TOPDIR)/bin/sdas6808

# override PORTDIR defined by super (parent) makefile
override PORTDIR = ../build/hc08

include $(srcdir)/../incl.mk

HC08_FLOAT = $(COMMON_FLOAT)

HC08_INT = $(COMMON_INT) \
  _divsint.c \
  _modsint.c \
  _moduint.c

HC08_LONG = $(COMMON_LONG)

HC08_SDCC = $(COMMON_SDCC) \
  _itoa.c \
  _ltoa.c \
  _spx.c \
  _startup.c \
  _strlen.c \
  _memmove.c \
  _heap.c \
  sprintf.c \
  vprintf.c

HC08SOURCES = $(addprefix ../,$(HC08_FLOAT) $(HC08_INT) $(HC08_LONG) $(HC08_SDCC))
HC08OBJECTS = $(patsubst %.c,%.rel,$(HC08_FLOAT) $(HC08_INT) $(HC08_LONG) $(HC08_SDCC))

OBJ = _ret.rel _divuint.rel _divulong.rel _mulint.rel _mullong.rel

LIB = hc08.lib
CC = $(SCC)
AS = $(SAS)
ASFLAGS = -plosgff

CFLAGS = -I$(srcdir)/../../include -I. --std-c99

all: $(PORTDIR)/$(LIB)

$(PORTDIR)/$(LIB): $(OBJ) $(HC08OBJECTS) Makefile
ifeq ($(LIB_TYPE), SDCCLIB)
	rm -f $@; \
	../../../bin/sdcclib -a $@ $(OBJ) $(HC08OBJECTS)
else
  ifeq ($(LIB_TYPE), AR)
	$(AR_S) -cq $@ $(OBJ) $(HC08OBJECTS)
  else
    ifeq ($(LIB_TYPE), RANLIB)
	$(AR_S) -cq $@ $(OBJ) $(HC08OBJECTS)
	$(top_builddir)/bin/asranlib $@
    else
	rm -f $@
	for i in $(basename $(OBJ) $(HC08OBJECTS)); do echo $$i >>$@; done
	cp $(OBJ) $(HC08OBJECTS) $(PORTDIR)
    endif
  endif
endif

%.rel: %.c
	$(CC) $(CFLAGS) -c $<

%.rel: ../%.c
	$(CC) $(CFLAGS) -c $<

clean:
	rm -f *.rel *.sym *.lst *~ $(CLEANSPEC) *.dump* *.asm *.lib

distclean: clean
	rm -f Makefile
